<?php
session_start();		//启动session
if(!isset($_SESSION['username']) || empty($_SESSION['username'])){
	header("location:/demo/login.php");
	eixt();
}

// 链接数据库
$link= mysqli_connect("127.0.0.1", "root", "", "demo");

//准备sql
$sql="select * from users";

//php执行sql查询
$result =mysqli_query($link,$sql);

//从结果集中获取数组
$result = mysqli_fetch_all($result);

$str="";
foreach ($result as $key => $val) {
	# code...
	$id=$val[0];
	$username=$val[1];
	$age=$val[2];
	$sex=$val[3];
	$image=$val[4];
	if($sex==1){
		$sex="男";
	}else{
		$sex="女";
	}

	$str.=<<<EOF
		<tr>
				<td>$id</td>
				<td>$username</td>
				<td>$age</td>
				<td>$sex</td>
				<td><img class="img" src="/demo/$image"/></td>
				<td>
					<a href="/demo/delete.php?id=$id">删除</a>|
					<a href="/demo/update.php?id=$id">修改</a>
				</td>
			</tr>
EOF;
}
// var_dump($str);
?>



<!DOCTYPE html>
<html>
<head>
	<title></title>
	<link rel="stylesheet" type="text/css" href="./css/bootstrap.min.css">
	<style type="">
		table{
			/*塌陷/合并*/
			border-collapse: collapse;		
		}
		.img{
			max-width: 150px;
			max-height: 50px;
		}
	</style>
</head>
<body>
	<div class="container">
		<h1>列表页</h1>
		<a href="/demo/logout.php">退出登录</a>
		<table class="table table-border">
			<thead>
				<th>序号</th>
				<th>用户名</th>
				<th>年龄</th>
				<th>性别</th>
				<th>图片</th>
				<th>编辑</th>
			</thead>
			<tbody>
				<?php
				 echo $str;
				?>
			</tbody>
		</table>
	</div>
	
</body>
</html>